package com.example.project.projectspringcloud.controller.front.sys;

import com.example.project.projectspringcloud.entity.sys.Area;
import com.example.project.projectspringcloud.service.sys.SysAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "城市地区Controller")
@Controller
@RequestMapping(value = "/area")
public class AreaController {

    private final String[] initials = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(",");

    @Autowired
    private SysAreaService sysAreaService;

    @ApiOperation(value = "地区选择页面", notes = "返回地区选择页面")
    @GetMapping(value = "/selector")
    public String selector(Area area, Model model) {
        area.setIsOpen(1);
        area.setOrderStr("order by initial");
        List<Area> areas = sysAreaService.list(area, null);
        model.addAttribute("areas", areas);
        model.addAttribute("initials", initials);
        return "m/content/order/order-city-selector";
    }
}
